<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/pages/common/component.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>修改债权信息</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<script type="text/javascript">
var oprateAction = "creditDebtAction.do";

$(document).ready(function() {
	// 借款时间
	configDate('loanDate', '<fmt:formatDate value="${creditDebtVO.loanDate}" pattern="yyyy-MM-dd" type="date"/>', 'yy-mm-dd');
	// 还款时间
	configDate('deadlineDate', '<fmt:formatDate value="${creditDebtVO.deadlineDate}" pattern="yyyy-MM-dd" type="date"/>', 'yy-mm-dd');
    // 校验主表单
    $("#creditDebtform").validationEngine();
});

// 返回账户列表
function back2list(){
	if(confirm("数据没有保存!确认将丢失当前表单数据!")){
		window.location.href = oprateAction+"?method=list"
	}else{
		return ;
	}
}

// 新增债权明细
function addCreditList4Create(){
	var tr = $('#tr_creditList');
	// 动态添加tr的ID索引
	var idx = $('#tab_creditList tr').length - 1;
	// 填充HTML
	var addHtml = '';
	addHtml += '<tr id="tr_creditList_'+idx+'" align="center" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor=\'#FCFDEE\';" onMouseOut="javascript:this.bgColor=\'#FFFFFF\';" height="22">';
	addHtml += '<td width="4%">时间</td>';
	addHtml += '<td width="8%">';
	addHtml += '<input id="pay_date_'+idx+'" name="payDate" style="width:100%;"/>';
	addHtml += '</td>';
	addHtml += '<td width="6%">收入账户</td>';
	addHtml += '<td width="11%">';
	addHtml += '<select id="accountId_'+idx+'" name="accountId" style="width:100%;" />';
	addHtml += '</td>';
	addHtml += '<td width="4%">金额</td>';
	addHtml += '<td width="6%">';
	addHtml += '<input class="validate[required,custom[number]]" id="amount_'+idx+'" name="amount" style="width:100%;"/>';
	addHtml += '</td>';
	addHtml += '<td width="4%">利息</td>';
	addHtml += '<td width="6%">';
	addHtml += '<input class="validate[required,custom[number]]" id="interest_'+idx+'" name="interest" style="width:100%;"/>';
	addHtml += '</td>';
	addHtml += '<td width="4%">备注</td>';
	addHtml += '<td width="12%">';
	addHtml += '<input name="note" style="width:100%;"/>';
	addHtml += '</td>';
	addHtml += '<td width="4%">';
	addHtml += '<a onclick="delCreditList('+idx+')">删除</a>';
	addHtml += '</td>';
	addHtml += '</tr>';
	
	// 添加到明细列表
	tr.after(addHtml);
	// 时间选择
	configDate('pay_date_'+idx, '<fmt:formatDate value="<%=new Date() %>" pattern="yyyy-MM-dd" type="date"/>', 'yy-mm-dd');
	// 填充账号信息select选项
	getAllAccount2Element('accountId_'+idx, '');
}

// 新增债权明细
function addCreditList4Edit(payDate, accountId, amount, interest, note){
	var tr = $('#tr_creditList');
	// 动态添加tr的ID索引
	var idx = $('#tab_creditList tr').length - 1;
	// 填充HTML
	var addHtml = '';
	addHtml += '<tr id="tr_creditList_'+idx+'" align="center" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor=\'#FCFDEE\';" onMouseOut="javascript:this.bgColor=\'#FFFFFF\';" height="22">';
	addHtml += '<td width="4%">时间</td>';
	addHtml += '<td width="8%">';
	addHtml += '<input id="pay_date_'+idx+'" name="payDate" style="width:100%;"/>';
	addHtml += '</td>';
	addHtml += '<td width="6%">收入账户</td>';
	addHtml += '<td width="11%">';
	addHtml += '<select id="accountId_'+idx+'" name="accountId" style="width:100%;" />';
	addHtml += '</td>';
	addHtml += '<td width="4%">金额</td>';
	addHtml += '<td width="6%">';
	addHtml += '<input class="validate[required,custom[number]]" id="amount_'+idx+'" name="amount" style="width:100%;" value="'+amount+'"/>';
	addHtml += '</td>';
	addHtml += '<td width="4%">利息</td>';
	addHtml += '<td width="6%">';
	addHtml += '<input class="validate[required,custom[number]]" id="interest_'+idx+'" name="interest" style="width:100%;" value="'+interest+'"/>';
	addHtml += '</td>';
	addHtml += '<td width="4%">备注</td>';
	addHtml += '<td width="12%">';
	addHtml += '<input name="note" style="width:100%;" value="'+note+'"/>';
	addHtml += '</td>';
	addHtml += '<td width="4%">';
	addHtml += '<a onclick="delCreditList('+idx+')">删除</a>';
	addHtml += '</td>';
	addHtml += '</tr>';
	
	// 添加到明细列表
	tr.after(addHtml);
	// 时间选择
	configDate('pay_date_'+idx, payDate.substring(0, 10), 'yy-mm-dd');
	// 填充账号信息select选项
	getAllAccount2Element('accountId_'+idx, accountId);
}

// 删除债权明细
function delCreditList(idx){
	$('#tr_creditList_'+idx).remove();
}
</script>	
	
</head>
  
  <body>
   <html:form styleId="creditDebtform" method="post" action="creditDebtAction.do">
    <input type="hidden" name="method" value="update"/>
    <input type="hidden" name="creditDebtId" value="${creditDebtVO.creditDebtId }"/>
    <br/><br/><br/><br/>
    <table id="datatable" width="40%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
		<tr align="center" bgcolor="#FAFAF1" height="22">
			<td colspan="2"><b>修改债权</b></td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td width="10%">债权人</td>
			<td width="30%">
				<input type="hidden" name="creatorId" value="${objLoginUser.userId }"/>
				${objLoginUser.name }
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td width="10%">债务人</td>
			<td width="30%">
				<input class="validate[required]" id="debtor" name="debtor" style='width:30%;' value="${creditDebtVO.debtor }"/>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>金额</td>
			<td>
				<input class="validate[required,custom[number]]" id="newAmount" name="newAmount" style='width:30%;' value="${creditDebtVO.amount }"/>
				<input type="hidden" name="amount" value="${creditDebtVO.amount }"/>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>利息</td>
			<td>
				<input class="validate[required,custom[number]]" id="newInterest" name="newInterest" style='width:30%;' value="${creditDebtVO.interest }"/>
				<input type="hidden" name="interest" style='width:30%;' value="${creditDebtVO.interest }"/>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>借款时间</td>
			<td>
				<input class="validate[required] text-input" id="loanDate" name="loanDate" style='width:30%;' readonly value="${creditDebtVO.loanDate }"/>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>承诺还款时间</td>
			<td>
				<input id="deadlineDate" name="deadlineDate" style='width:30%;' readonly value="${creditDebtVO.deadlineDate }"/>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>借出账户</td>
			<td>
				<input type="hidden" name="outAccountId" value="${creditDebtVO.outAccount.accountId }"/>
				<select name="newOutAccountId" style='width:30%;' >
					<c:forEach var="account" items="${lstAccountVOs}">
						<option value="${account.accountId }" ${creditDebtVO.outAccount.accountId==account.accountId ? 'selected' : ''} >${account.accountName}:${account.amount}</option>
					</c:forEach>	
				</select>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>备注</td>
			<td>
				<input id="note" name="note" style='width:30%;' value="${creditDebtVO.note }"/>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<html:submit value="提交"></html:submit>
				&nbsp;&nbsp;&nbsp;
				<input type="button" value="返回" onclick="back2list();"> 
			</td>
		</tr>
    </table>
   </html:form> 
   
<html:form styleId="creditDebtListform" method="post" action="creditDebtAction.do">
  <input type="hidden" name="method" value="updateList"/>
  <input type="hidden" name="creatorId" value="${objLoginUser.userId }"/>
  <input type="hidden" name="creditDebtId" value="${creditDebtVO.creditDebtId }"/>
  <table id="tab_creditList" width="65%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
	<tr id="tr_creditList" align="center" bgcolor="#FAFAF1" height="22">
		<td colspan="11">
			<b>收款明细</b>
			&nbsp;&nbsp;<b style="color: red"><a onclick="addCreditList4Create();">增加</a></b>
			&nbsp;&nbsp;<html:submit value="保存"></html:submit>
		</td>
	</tr>
	<c:forEach var="creditDebtListVO" items="${setCreditDebtListVOs}" varStatus="status">
		<script>addCreditList4Edit('<c:out value="${creditDebtListVO.payDate}"/>', '<c:out value="${creditDebtListVO.account.accountId}"/>', '<c:out value="${creditDebtListVO.amount}"/>', '<c:out value="${creditDebtListVO.interest}"/>', '<c:out value="${creditDebtListVO.note}"/>')</script>
		<!-- 
		<tr id="tr_creditList_${status.index }" align="center" bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor=\'#FCFDEE\';" onMouseOut="javascript:this.bgColor=\'#FFFFFF\';" height="22">
			<td width="4%">时间</td>
			<td width="8%"><input id="pay_date_${status.index }" name="payDate" style="width:100%;"/></td>
			<td width="6%">收入账户</td>
			<td width="11%"><select id="accountId_${status.index }" name="accountId" style="width:100%;" /></td>
			<td width="4%">金额</td>
			<td width="6%"><input name="amount" style="width:100%;" value="${creditDebtListVO.amount }"/></td>
			<td width="4%">利息</td>
			<td width="6%"><input name="interest" style="width:100%;" value="${creditDebtListVO.interest }"/></td>
			<td width="4%">备注</td>
			<td width="12%"><input name="note" style="width:100%;" value="${creditDebtListVO.note }"/></td>
			<td width="4%"><a onclick="delCreditList('${status.index }')">删除</a></td>
		</tr>
		-->
	</c:forEach>
  </table>
</html:form>    
  </body>
</html>
